/*
 * A palindromic number reads the same both ways. The largest palindrome
 * made from the product of two 2-digit numbers is 9009 = 91  99.
 * 
 * Find the largest palindrome made from the product of two 3-digit numbers.
 */
package pj1;

import java.util.ArrayList;

class Problem4 {
	
	static final int problem1 = 101;
	static final int problem2 = 1000;
	
	public static void main(String[] args) {
		ArrayList<Integer> palindrome = new ArrayList<Integer>();
		Integer big = 0;
		Integer test = 0;
		StringBuilder testString;
		StringBuilder reversed;

		// palindrome candidate testing
		for (int i=problem1; i < problem2; i++) {
			for (int j=problem1; j < problem2; j++) {
				test = i*j;
				testString = new StringBuilder(test.toString());
				reversed = testString.reverse();
				if (test.toString().equals(reversed.toString())) {
					palindrome.add(test);
					break;
				}
			}
		}
		
		// return the largest product
		for (Integer n : palindrome) {
			big = (n > big) ? n : big; 
		}
		
		System.out.println(big.toString());
	}
}
